namespace nDeveloper.VSS.IVSSFunctionLibrary
{
    using SourceSafeTypeLib;
    using System;
    using System.Runtime.InteropServices;

    public class clIVSSLibrary
    {
        public long AddItemCount = 0L;
        public long BranchItemCount = 0L;
        public long CheckInItemCount = 0L;
        public long CheckOutCommentCount = 0L;
        public long CheckOutDateCount = 0L;
        public long CheckOutItemCount = 0L;
        public long CheckOutLocalSpecCount = 0L;
        public long CheckOutMachineCount = 0L;
        public long CheckOutUserNameCount = 0L;
        public long CheckOutVersionNumberCount = 0L;
        public long CreateProjectCount = 0L;
        private string CurrentPassword;
        public long DatabaseAddUserCount = 0L;
        public long DatabaseDeleteUserCount = 0L;
        public long DatabaseEnableRightsCount = 0L;
        public long DatabaseGetCurrentProjectCount = 0L;
        public long DatabaseGetDBNameCount = 0L;
        public long DatabaseGetDefaultRightsCount = 0L;
        public long DatabaseGetItemCount = 0L;
        public long DatabaseGetItemCountsCount = 0L;
        public long DatabaseGetSrcSafeINICount = 0L;
        public long DatabaseGetUserCount = 0L;
        public long DatabaseGetUserNamesCount = 0L;
        public long DatabaseGetVersionCount = 0L;
        public long DatabaseSetCurrentProjectCount = 0L;
        public long DatabaseSetDefaultRightsCount = 0L;
        public long DatabaseUserNameCount = 0L;
        public long DatabaseUsersCount = 0L;
        public long DestroyItemCount = 0L;
        public long DiffItemsCount = 0L;
        public long GetItemBinaryCount = 0L;
        public long GetItemCheckOutsCount = 0L;
        public long GetItemChildCount = 0L;
        public long GetItemCount = 0L;
        public long GetItemDeletedCount = 0L;
        public long GetItemIsCheckedOutCount = 0L;
        public long GetItemLinksCount = 0L;
        public long GetItemNameCount = 0L;
        public long GetItemParentCount = 0L;
        public long GetItemTypeCount = 0L;
        public long GetItemVersionCount = 0L;
        public long GetItemVersionCountsCount = 0L;
        public long MoveItemCount = 0L;
        public long OpenMethodCount = 0L;
        private const string proj_Root = "$/";
        public long SetItemCheckOutFolderCount = 0L;
        public long SetItemDeletedCount = 0L;
        public long SetItemLabelCount = 0L;
        public long SetItemNameCount = 0L;
        public long SetItemTypeCount = 0L;
        public long ShareItemCount = 0L;
        public long UnCheckOutItemCount = 0L;
        public long UserChangePasswordCount = 0L;
        public long UserGetNameCount = 0L;
        public long UserGetReadOnlyCount = 0L;
        public long UserGetRightsCount = 0L;
        public long UserRemoveRightsCount = 0L;
        public long UserSetNameCount = 0L;
        public long UserSetReadOnlyCount = 0L;
        public long UserSetRightsCount = 0L;
        public long VersionActionCount = 0L;
        public long VersionCommentCount = 0L;
        public long VersionDateCount = 0L;
        public long VersionLabelCount = 0L;
        public long VersionLabelCountCommentCount = 0L;
        public long VersionSpecCount = 0L;
        public long VersionUserNameCount = 0L;
        public long VersionVersionCount = 0L;
        private VSSDatabase VSS_Database;

        public string AddItem(string ParentProject, string ItemToAddPath, string AddComment, int Flags)
        {
            try
            {
                this.VSS_Database.get_VSSItem(ParentProject, false).Add(ItemToAddPath, AddComment, Flags);
                this.AddItemCount += 1L;
            }
            catch (Exception exception)
            {
                return exception.ToString();
            }
            return "";
        }

        public string AddUser(string UserName, string Password, bool ReadOnly)
        {
            try
            {
                this.VSS_Database.AddUser(UserName, Password, ReadOnly);
                this.DatabaseAddUserCount += 1L;
            }
            catch (Exception exception)
            {
                return exception.ToString();
            }
            return "";
        }

        public string AreProjectRightsEnabled(ref bool Enabled)
        {
            try
            {
                Enabled = this.VSS_Database.ProjectRightsEnabled;
                this.DatabaseEnableRightsCount += 1L;
            }
            catch (Exception exception)
            {
                return exception.ToString();
            }
            return "";
        }

        public string BranchItem(string ItemToBranch, string Comment, int Flags)
        {
            try
            {
                VSSItem item = this.VSS_Database.get_VSSItem(ItemToBranch, false);
                this.DatabaseGetItemCount += 1L;
                item.Branch(Comment, Flags);
                this.BranchItemCount += 1L;
            }
            catch (Exception exception)
            {
                return exception.ToString();
            }
            return "";
        }

        public string ChangePassword(string NewPassword, string UserName)
        {
            try
            {
                VSSUser user = this.VSS_Database.get_User(UserName);
                this.DatabaseGetUserCount += 1L;
                user.Password = NewPassword;
                this.UserChangePasswordCount += 1L;
            }
            catch (Exception exception)
            {
                return exception.ToString();
            }
            return "";
        }

        public string ChangeUserName(string UserName, string NewName)
        {
            try
            {
                VSSUser user = this.VSS_Database.get_User(UserName);
                this.DatabaseGetUserCount += 1L;
                user.Name = NewName;
                this.UserSetNameCount += 1L;
            }
            catch (Exception exception)
            {
                return exception.ToString();
            }
            return "";
        }

        public string ChangeUserReadOnlyRights(string UserName, bool ReadOnly)
        {
            try
            {
                VSSUser user = this.VSS_Database.get_User(UserName);
                this.DatabaseGetUserCount += 1L;
                user.ReadOnly = ReadOnly;
                this.UserSetReadOnlyCount += 1L;
            }
            catch (Exception exception)
            {
                return exception.ToString();
            }
            return "";
        }

        public string CheckInItem(string ItemToCheckIn, string CheckInPath, ref string Comment, int Flags)
        {
            try
            {
                this.VSS_Database.get_VSSItem(ItemToCheckIn, false).Checkin(Comment, CheckInPath, Flags);
                this.CheckInItemCount += 1L;
            }
            catch (Exception exception)
            {
                return exception.ToString();
            }
            return "";
        }

        public string CheckOutItem(string ItemToCheckOut, string CheckOutPath, ref string Comment, int Flags)
        {
            try
            {
                this.VSS_Database.get_VSSItem(ItemToCheckOut, false).Checkout(Comment, CheckOutPath, Flags);
                this.CheckOutItemCount += 1L;
            }
            catch (Exception exception)
            {
                return exception.ToString();
            }
            return "";
        }

        public string CheckOutVersion(string Comment, string ItemPath, int VersionNumber, string LocalPath, int Flags)
        {
            try
            {
                VSSItem item = this.VSS_Database.get_VSSItem(ItemPath, false);
                this.DatabaseGetItemCount += 1L;
                VSSItem item2 = item.get_Version(VersionNumber);
                this.DatabaseGetVersionCount += 1L;
                item2.Checkout(Comment, LocalPath, 0);
                this.CheckOutItemCount += 1L;
            }
            catch (Exception exception)
            {
                return exception.ToString();
            }
            return "";
        }

        public string CheckOutVersionByLabel(string Comment, string ItemPath, string VersionLabelCount, string LocalPath, int Flags)
        {
            try
            {
                VSSItem item = this.VSS_Database.get_VSSItem(ItemPath, false);
                this.DatabaseGetItemCount += 1L;
                VSSItem item2 = item.get_Version(VersionLabelCount);
                this.GetItemVersionCount += 1L;
                item2.Checkout(Comment, LocalPath, 0);
                this.CheckOutItemCount += 1L;
            }
            catch (Exception exception)
            {
                return exception.ToString();
            }
            return "";
        }

        public string CloseDB()
        {
            try
            {
                this.VSS_Database = null;
            }
            catch (Exception exception)
            {
                return exception.ToString();
            }
            return "";
        }

        public string CreateProject(string Parent, string ProjectName, string Comment)
        {
            try
            {
                this.VSS_Database.get_VSSItem(Parent, false).NewSubproject(ProjectName, Comment);
                this.CreateProjectCount += 1L;
            }
            catch (Exception exception)
            {
                return exception.ToString();
            }
            return "";
        }

        public string DeleteItem(string ItemToDelete, bool Destroy)
        {
            bool deleted = false;
            try
            {
                this.IsItemDeleted(ItemToDelete, ref deleted);
                IVSSItem item = this.VSS_Database.get_VSSItem(ItemToDelete, deleted);
                this.DatabaseGetItemCount += 1L;
                if (!Destroy)
                {
                    item.Deleted = true;
                    this.SetItemDeletedCount += 1L;
                }
                else
                {
                    item.Destroy();
                    this.DestroyItemCount += 1L;
                }
            }
            catch (Exception exception)
            {
                return exception.ToString();
            }
            return "";
        }

        public string DeleteUser(string UserName)
        {
            try
            {
                IVSSUser user = this.VSS_Database.get_User(UserName);
                this.DatabaseGetUserCount += 1L;
                user.Delete();
                this.DatabaseDeleteUserCount += 1L;
            }
            catch (Exception exception)
            {
                return exception.ToString();
            }
            return "";
        }

        public string DoItemsDiffer(string VSSItemToDiff, string LocalItemToDiff, ref bool ItemsDiff)
        {
            try
            {
                IVSSItem item = this.VSS_Database.get_VSSItem(VSSItemToDiff, false);
                this.DatabaseGetItemCount += 1L;
                ItemsDiff = item.get_IsDifferent(LocalItemToDiff);
                this.DiffItemsCount += 1L;
            }
            catch (Exception exception)
            {
                return exception.ToString();
            }
            return "";
        }

        public string EnabledProjectRights(bool Enable)
        {
            try
            {
                this.VSS_Database.ProjectRightsEnabled = Enable;
                this.DatabaseEnableRightsCount += 1L;
            }
            catch (Exception exception)
            {
                return exception.ToString();
            }
            return "";
        }

        public string GetCheckOutFolder(string ItemPath, string UserName, ref string CheckOutPath)
        {
            CheckOutPath = "";
            try
            {
                foreach (VSSCheckout checkout in this.VSS_Database.get_VSSItem(ItemPath, false).Checkouts)
                {
                    this.CheckOutUserNameCount += 1L;
                    if (checkout.Username == UserName)
                    {
                        CheckOutPath = checkout.LocalSpec;
                        this.CheckOutLocalSpecCount += 1L;
                        break;
                    }
                }
                this.GetItemCheckOutsCount += 1L;
            }
            catch (Exception exception)
            {
                return exception.ToString();
            }
            return "";
        }

        public string GetCheckOutInfo(out string[,] CheckOutData, string FilePath)
        {
            VSSItem item = this.VSS_Database.get_VSSItem(FilePath, false);
            this.DatabaseGetItemCount += 1L;
            int count = item.Checkouts.Count;
            this.GetItemCheckOutsCount += 1L;
            CheckOutData = new string[count, 8];
            try
            {
                int num2 = 0;
                foreach (VSSCheckout checkout in item.Checkouts)
                {
                    CheckOutData[num2, 0] = checkout.Username;
                    this.CheckOutUserNameCount += 1L;
                    CheckOutData[num2, 1] = checkout.Date.ToString();
                    this.CheckOutDateCount += 1L;
                    CheckOutData[num2, 2] = checkout.VersionNumber.ToString();
                    this.CheckOutVersionNumberCount += 1L;
                    CheckOutData[num2, 3] = checkout.Machine;
                    this.CheckOutMachineCount += 1L;
                    CheckOutData[num2, 4] = checkout.LocalSpec;
                    this.CheckOutLocalSpecCount += 1L;
                    if (item.Parent.Name == "")
                    {
                        this.GetItemParentCount += 1L;
                        CheckOutData[num2, 5] = "$/";
                    }
                    else
                    {
                        this.GetItemParentCount += 1L;
                        CheckOutData[num2, 5] = item.Parent.Name;
                    }
                    CheckOutData[num2, 6] = checkout.Comment;
                    this.CheckOutCommentCount += 1L;
                    CheckOutData[num2, 7] = item.Name;
                    this.GetItemNameCount += 1L;
                    num2++;
                }
                this.GetItemCheckOutsCount += 1L;
            }
            catch (Exception exception)
            {
                return exception.ToString();
            }
            return "";
        }

        public string GetCheckOutState(string FilePath, ref int CheckOutStatus)
        {
            try
            {
                VSSItem item = this.VSS_Database.get_VSSItem(FilePath, false);
                this.DatabaseGetItemCount += 1L;
                CheckOutStatus = item.IsCheckedOut;
                this.GetItemIsCheckedOutCount += 1L;
            }
            catch (Exception exception)
            {
                return exception.ToString();
            }
            return "";
        }

        public string GetChildren(string ProjectPath, bool ProjectDeleted, out string[,] Children, bool IncludeDeleted)
        {
            VSSItem item = this.VSS_Database.get_VSSItem(ProjectPath, ProjectDeleted);
            int count = item.get_Items(IncludeDeleted).Count;
            this.GetItemChildCount += 1L;
            int num2 = 0;
            Children = new string[count, 11];
            count = 0;
            try
            {
                IVSSItems items = item.get_Items(IncludeDeleted);
                this.DatabaseGetItemCount += 1L;
                foreach (VSSItem item2 in items)
                {
                    Children[num2, count] = item2.Name;
                    this.GetItemNameCount += 1L;
                    count++;
                    Children[num2, count] = item2.Type.ToString();
                    this.GetItemTypeCount += 1L;
                    count++;
                    Children[num2, count] = item2.VersionNumber.ToString();
                    this.GetItemVersionCount += 1L;
                    count++;
                    if (item2.Type == 1)
                    {
                        Children[num2, count] = item2.IsCheckedOut.ToString();
                        this.GetItemIsCheckedOutCount += 1L;
                        count++;
                        if (Children[num2, count] != "0")
                        {
                            foreach (IVSSCheckout checkout in item2.Checkouts)
                            {
                                Children[num2, count] = checkout.LocalSpec;
                                this.CheckOutLocalSpecCount += 1L;
                                count++;
                                Children[num2, count] = checkout.Comment;
                                this.CheckOutCommentCount += 1L;
                                count++;
                                if (item2.Checkouts.Count > 1)
                                {
                                    if (item2.IsCheckedOut == 2)
                                    {
                                        Children[num2, count] = this.VSS_Database.Username + "...";
                                        this.DatabaseUserNameCount += 1L;
                                    }
                                    else
                                    {
                                        Children[num2, count] = checkout.Username + "...";
                                        this.CheckOutUserNameCount += 1L;
                                    }
                                    this.GetItemIsCheckedOutCount += 1L;
                                    count++;
                                    Children[num2, count] = "1";
                                }
                                else
                                {
                                    Children[num2, count] = checkout.Username;
                                    this.CheckOutUserNameCount += 1L;
                                    count++;
                                    Children[num2, count] = "0";
                                }
                                this.GetItemCheckOutsCount += 1L;
                                count++;
                                break;
                            }
                            this.GetItemCheckOutsCount += 1L;
                        }
                        count = 8;
                        this.GetFileDate(item2, ref Children[num2, count]);
                        count++;
                        if (item2.Links.Count != 1)
                        {
                            Children[num2, count] = "1";
                        }
                        else
                        {
                            Children[num2, count] = "0";
                        }
                        this.GetItemLinksCount += 1L;
                        count++;
                    }
                    this.GetItemTypeCount += 1L;
                    count = 10;
                    if (item2.Deleted || item.Deleted)
                    {
                        Children[num2, count] = "1";
                    }
                    else
                    {
                        Children[num2, count] = "0";
                    }
                    this.GetItemDeletedCount += 2L;
                    count = 0;
                    num2++;
                }
                this.DatabaseGetItemCountsCount += 1L;
            }
            catch (Exception exception)
            {
                return exception.ToString();
            }
            return "";
        }

        public string GetCurrentProject()
        {
            this.DatabaseGetCurrentProjectCount += 1L;
            return this.VSS_Database.CurrentProject;
        }

        public string GetDatabaseName(ref string DataBaseName)
        {
            try
            {
                DataBaseName = this.VSS_Database.DatabaseName;
                this.DatabaseGetDBNameCount += 1L;
            }
            catch (Exception exception)
            {
                return exception.ToString();
            }
            return "";
        }

        public string GetDefaultUserRights(ref int Rights)
        {
            try
            {
                Rights = this.VSS_Database.DefaultProjectRights;
                this.DatabaseGetDefaultRightsCount += 1L;
            }
            catch (Exception exception)
            {
                return exception.ToString();
            }
            return "";
        }

        public string GetDeletedItems(out string[,] DeletedItems, string ProjectPath)
        {
            int num2 = 0;
            VSSItem item = this.VSS_Database.get_VSSItem(ProjectPath, false);
            this.DatabaseGetItemCount += 1L;
            foreach (VSSItem item2 in item.get_Items(true))
            {
                if (item2.Deleted)
                {
                    num2++;
                }
                this.GetItemDeletedCount += 1L;
            }
            this.DatabaseGetItemCountsCount += 1L;
            DeletedItems = new string[num2, 2];
            try
            {
                int num = 0;
                foreach (VSSItem item3 in item.get_Items(true))
                {
                    if (item3.Deleted)
                    {
                        DeletedItems[num, 0] = item3.Name;
                        this.GetItemNameCount += 1L;
                        DeletedItems[num, 1] = item3.Type.ToString();
                        this.GetItemTypeCount += 1L;
                        num++;
                    }
                    this.GetItemDeletedCount += 1L;
                }
                this.DatabaseGetItemCountsCount += 1L;
            }
            catch (Exception exception)
            {
                return exception.ToString();
            }
            return "";
        }

        public string GetFileDate(VSSItem VSS_File, ref string FileDate)
        {
            try
            {
                if (VSS_File.Checkouts.Count != 0)
                {
                    foreach (VSSCheckout checkout in VSS_File.Checkouts)
                    {
                        FileDate = checkout.Date.ToString();
                        this.CheckOutDateCount += 1L;
                        break;
                    }
                    this.GetItemCheckOutsCount += 1L;
                }
                else
                {
                    bool flag = false;
                    foreach (IVSSVersion version in VSS_File.get_Versions(0))
                    {
                        if (!flag)
                        {
                            FileDate = version.Date.ToString();
                        }
                        this.CheckOutDateCount += 1L;
                        flag = true;
                    }
                    this.GetItemVersionCountsCount += 1L;
                }
                this.GetItemCheckOutsCount += 1L;
            }
            catch (Exception exception)
            {
                return exception.ToString();
            }
            return "";
        }

        public string GetHistory(out string[,] ItemData, string ItemPath, int Flags)
        {
            int num = 0;
            VSSItem item = this.VSS_Database.get_VSSItem(ItemPath, false);
            this.DatabaseGetItemCount += 1L;
            foreach (IVSSVersion version in item.get_Versions(Flags))
            {
                num++;
            }
            this.GetItemVersionCountsCount += 1L;
            ItemData = new string[num, 9];
            try
            {
                num = 0;
                foreach (IVSSVersion version2 in item.get_Versions(Flags))
                {
                    ItemData[num, 0] = version2.VersionNumber.ToString();
                    this.VersionVersionCount += 1L;
                    ItemData[num, 1] = version2.Username;
                    this.VersionUserNameCount += 1L;
                    ItemData[num, 2] = version2.Date.ToString();
                    this.VersionDateCount += 1L;
                    ItemData[num, 3] = version2.Action;
                    this.VersionActionCount += 1L;
                    ItemData[num, 4] = version2.Label;
                    this.VersionLabelCount += 1L;
                    ItemData[num, 5] = version2.LabelComment;
                    this.VersionLabelCountCommentCount += 1L;
                    ItemData[num, 6] = version2.VSSItem.Name;
                    this.GetItemNameCount += 1L;
                    ItemData[num, 7] = version2.Comment;
                    this.VersionCommentCount += 1L;
                    ItemData[num, 8] = item.Spec;
                    this.VersionSpecCount += 1L;
                    num++;
                }
            }
            catch (Exception exception)
            {
                return exception.ToString();
            }
            return "";
        }

        public string GetItem(string ItemToGet, ref string GetPath, int Flags)
        {
            try
            {
                this.VSS_Database.get_VSSItem(ItemToGet, false).Get(ref GetPath, Flags);
                this.GetItemCount += 1L;
            }
            catch (Exception exception)
            {
                return exception.ToString();
            }
            return "";
        }

        public string GetLatestVersionInfo(out string[] ItemData, string ItemPath, int WhatToFind)
        {
            bool flag = false;
            ItemData = new string[3];
            try
            {
                VSSItem item = this.VSS_Database.get_VSSItem(ItemPath, false);
                this.DatabaseGetItemCount += 1L;
                foreach (IVSSVersion version in item.get_Versions(0))
                {
                    switch (WhatToFind)
                    {
                        case 1:
                        {
                            if (!flag && (version.Comment.Length != 0))
                            {
                                flag = true;
                                ItemData[0] = version.Comment;
                                this.VersionCommentCount += 1L;
                                ItemData[1] = version.VersionNumber.ToString();
                                this.VersionVersionCount += 1L;
                                ItemData[2] = version.Date.ToString();
                                this.VersionDateCount += 1L;
                            }
                            continue;
                        }
                        case 2:
                        {
                            if (!flag && (version.Label.Length != 0))
                            {
                                flag = true;
                                ItemData[0] = version.Label;
                                this.VersionLabelCount += 1L;
                                ItemData[1] = version.VersionNumber.ToString();
                                this.VersionVersionCount += 1L;
                                ItemData[2] = version.Date.ToString();
                                this.VersionDateCount += 1L;
                            }
                            continue;
                        }
                        case 3:
                        {
                            if (!flag)
                            {
                                ItemData[0] = item.VersionNumber.ToString();
                                this.VersionVersionCount += 1L;
                                flag = true;
                            }
                            continue;
                        }
                        case 4:
                        {
                            if (!flag)
                            {
                                ItemData[0] = version.Date.ToString();
                                this.VersionDateCount += 1L;
                                flag = true;
                            }
                            continue;
                        }
                        case 5:
                        {
                            if (!flag && (version.LabelComment.Length != 0))
                            {
                                flag = true;
                                ItemData[0] = version.LabelComment;
                                this.VersionCommentCount += 1L;
                                ItemData[1] = version.VersionNumber.ToString();
                                this.VersionVersionCount += 1L;
                                ItemData[2] = version.Date.ToString();
                                this.VersionDateCount += 1L;
                            }
                            continue;
                        }
                    }
                }
                this.GetItemVersionCountsCount += 1L;
            }
            catch (Exception exception)
            {
                return exception.ToString();
            }
            return "";
        }

        public string GetLinksInfo(out string[] LinksData, string FilePath)
        {
            VSSItem item = this.VSS_Database.get_VSSItem(FilePath, false);
            this.DatabaseGetItemCount += 1L;
            int count = item.Links.Count;
            LinksData = new string[count];
            try
            {
                int index = 0;
                foreach (VSSItem item2 in item.Links)
                {
                    LinksData[index] = item2.Parent.Spec;
                    this.GetItemParentCount += 1L;
                    index++;
                }
                this.GetItemLinksCount += 1L;
            }
            catch (Exception exception)
            {
                return exception.ToString();
            }
            return "";
        }

        public string GetSrcSafeINIPath()
        {
            this.DatabaseGetSrcSafeINICount += 1L;
            return this.VSS_Database.SrcSafeIni;
        }

        public int GetUserCount()
        {
            this.DatabaseUsersCount += 1L;
            return this.VSS_Database.Users.Count;
        }

        public string GetUserData(out string[,] UserData)
        {
            int num = 0;
            int count = 0;
            count = this.VSS_Database.Users.Count;
            this.DatabaseUsersCount += 1L;
            UserData = new string[count, 2];
            try
            {
                foreach (VSSUser user in this.VSS_Database.Users)
                {
                    UserData[num, 0] = user.Name;
                    this.UserGetNameCount += 1L;
                    UserData[num, 1] = user.ReadOnly.ToString();
                    this.UserGetReadOnlyCount += 1L;
                    num++;
                }
                this.DatabaseGetUserNamesCount += 1L;
            }
            catch (Exception exception)
            {
                return exception.ToString();
            }
            return "";
        }

        public string GetUserName(ref string UserName)
        {
            try
            {
                this.DatabaseUserNameCount += 1L;
                UserName = this.VSS_Database.Username;
            }
            catch (Exception exception)
            {
                return exception.ToString();
            }
            return "";
        }

        public string GetUserPassword(ref string UsersPassword)
        {
            try
            {
                UsersPassword = this.CurrentPassword;
            }
            catch (Exception exception)
            {
                return exception.ToString();
            }
            return "";
        }

        public string GetUserRights(string ProjectPath, string UserName, ref int Rights)
        {
            try
            {
                VSSUser user = this.VSS_Database.get_User(UserName);
                this.DatabaseGetUserCount += 1L;
                Rights = user.get_ProjectRights(ProjectPath);
                this.UserGetRightsCount += 1L;
            }
            catch (Exception exception)
            {
                return exception.ToString();
            }
            return "";
        }

        public string GetVersionByLabel(string ItemPath, string Label, string LocalPath, int Flags)
        {
            try
            {
                VSSItem item = this.VSS_Database.get_VSSItem(ItemPath, false);
                this.DatabaseGetItemCount += 1L;
                VSSItem item2 = item.get_Version(Label);
                this.DatabaseGetVersionCount += 1L;
                item2.Get(ref LocalPath, Flags);
                this.GetItemCount += 1L;
            }
            catch (Exception exception)
            {
                return exception.ToString();
            }
            return "";
        }

        public string GetVersionByVersionNumber(string ItemPath, int VersionNumber, string LocalPath, int Flags)
        {
            try
            {
                VSSItem item = this.VSS_Database.get_VSSItem(ItemPath, false);
                this.DatabaseGetItemCount += 1L;
                VSSItem item2 = item.get_Version(VersionNumber);
                this.DatabaseGetVersionCount += 1L;
                item2.Get(ref LocalPath, Flags);
                this.GetItemCount += 1L;
            }
            catch (Exception exception)
            {
                return exception.ToString();
            }
            return "";
        }

        public string GetWorkingFolder(string ProjectPath, ref string WorkingFolder, bool Deleted)
        {
            try
            {
                if (!Deleted)
                {
                    VSSItem item = this.VSS_Database.get_VSSItem(ProjectPath, Deleted);
                    this.DatabaseGetItemCount += 1L;
                    WorkingFolder = item.LocalSpec;
                    this.SetItemCheckOutFolderCount += 1L;
                }
                return "";
            }
            catch (Exception exception)
            {
                return exception.ToString();
            }
        }

        public string HasSubProject(out string[,] Children, string ProjectPath, bool ItemIsDeleted, bool IncludeDeleted)
        {
            Children = new string[0, 0];
            try
            {
                int num = 0;
                VSSItem item = this.VSS_Database.get_VSSItem(ProjectPath, ItemIsDeleted);
                IVSSItems items = item.get_Items(IncludeDeleted);
                this.DatabaseGetItemCount += 1L;
                foreach (VSSItem item2 in items)
                {
                    if (item2.Type == 0)
                    {
                        num++;
                    }
                    this.GetItemTypeCount += 1L;
                }
                this.DatabaseGetItemCountsCount += 1L;
                Children = new string[num, 2];
                num = 0;
                foreach (VSSItem item3 in items)
                {
                    if (item3.Type == 0)
                    {
                        Children[num, 0] = item3.Name;
                        this.GetItemNameCount += 1L;
                        if (item3.Deleted || item.Deleted)
                        {
                            Children[num, 1] = "True";
                        }
                        else
                        {
                            Children[num, 1] = item3.Deleted.ToString();
                            this.GetItemDeletedCount += 1L;
                        }
                        this.GetItemDeletedCount += 1L;
                        num++;
                    }
                    this.GetItemTypeCount += 1L;
                }
                this.DatabaseGetItemCountsCount += 1L;
            }
            catch (Exception exception)
            {
                return exception.ToString();
            }
            return "";
        }

        public string IsFileBinary(string FilePath, ref bool Binary)
        {
            try
            {
                VSSItem item = this.VSS_Database.get_VSSItem(FilePath, false);
                this.DatabaseGetItemCount += 1L;
                Binary = item.Binary;
                this.GetItemBinaryCount += 1L;
                return "";
            }
            catch (Exception exception)
            {
                return exception.ToString();
            }
        }

        public string IsFileCheckedOut(string FilePath, ref bool CheckOutState)
        {
            try
            {
                VSSItem item = this.VSS_Database.get_VSSItem(FilePath, false);
                this.DatabaseGetItemCount += 1L;
                CheckOutState = item.IsCheckedOut != 0;
                this.GetItemIsCheckedOutCount += 1L;
            }
            catch (Exception exception)
            {
                return exception.ToString();
            }
            return "";
        }

        public string IsFileCheckedOutMultiple(string FilePath, ref bool CheckedOutMultiple)
        {
            try
            {
                VSSItem item = this.VSS_Database.get_VSSItem(FilePath, false);
                this.DatabaseGetItemCount += 1L;
                CheckedOutMultiple = item.Checkouts.Count > 1;
                this.GetItemCheckOutsCount += 1L;
            }
            catch (Exception exception)
            {
                return exception.ToString();
            }
            return "";
        }

        public string IsItemDeleted(string FilePath, ref bool Deleted)
        {
            Deleted = false;
            try
            {
                VSSItem item = this.VSS_Database.get_VSSItem(FilePath, true);
                this.DatabaseGetItemCount += 1L;
                Deleted = item.Deleted;
                this.GetItemDeletedCount += 1L;
                return "";
            }
            catch (Exception exception)
            {
                if (exception.Message == "File or project not found")
                {
                    return "";
                }
                return exception.ToString();
            }
        }

        public string IsItemShared(string FilePath, ref bool Shared)
        {
            try
            {
                VSSItem item = this.VSS_Database.get_VSSItem(FilePath, false);
                this.DatabaseGetItemCount += 1L;
                Shared = item.Links.Count > 1;
                this.GetItemLinksCount += 1L;
                return "";
            }
            catch (Exception exception)
            {
                return exception.ToString();
            }
        }

        public string IsUserReadOnly(string UserName, ref bool ReadOnly)
        {
            try
            {
                VSSUser user = this.VSS_Database.get_User(UserName);
                this.DatabaseGetUserCount += 1L;
                ReadOnly = user.ReadOnly;
                this.UserGetReadOnlyCount += 1L;
            }
            catch (Exception exception)
            {
                return exception.ToString();
            }
            return "";
        }

        public string IsUserValid(string UserName, ref bool IsValidUser)
        {
            IsValidUser = false;
            try
            {
                foreach (VSSUser user in this.VSS_Database.Users)
                {
                    if (UserName.ToUpper() == user.Name.ToUpper())
                    {
                        IsValidUser = true;
                        this.DatabaseGetUserCount += 1L;
                        break;
                    }
                    this.DatabaseGetUserNamesCount += 1L;
                }
                return "";
            }
            catch (Exception exception)
            {
                return exception.ToString();
            }
        }

        public string LabelItem(string ItemToLabel, string Label, string Comment)
        {
            try
            {
                this.VSS_Database.get_VSSItem(ItemToLabel, false).Label(Label, Comment);
                this.SetItemLabelCount += 1L;
            }
            catch (Exception exception)
            {
                return exception.ToString();
            }
            return "";
        }

        public string MoveProject(string SourcePath, string TargetPath)
        {
            try
            {
                VSSItem item = this.VSS_Database.get_VSSItem(SourcePath, false);
                VSSItem pINewParent = this.VSS_Database.get_VSSItem(TargetPath, false);
                this.DatabaseGetItemCount += 2L;
                item.Move(pINewParent);
                this.MoveItemCount += 1L;
                return "";
            }
            catch (Exception exception)
            {
                return exception.ToString();
            }
        }

        public string OpenDB(string UserName, string PassWord, string Path)
        {
            this.VSS_Database = new VSSDatabaseClass();
            try
            {
                this.VSS_Database.Open(Path, UserName, PassWord);
                this.CurrentPassword = PassWord;
                this.OpenMethodCount += 1L;
            }
            catch (Exception exception)
            {
                return exception.ToString();
            }
            return "";
        }

        public string RecoverItem(string ItemToRecover)
        {
            try
            {
                this.VSS_Database.get_VSSItem(ItemToRecover, true).Deleted = false;
                this.SetItemDeletedCount += 1L;
            }
            catch (Exception exception)
            {
                return exception.ToString();
            }
            return "";
        }

        public string RemoveUserRights(string ProjectPath, string UserName)
        {
            try
            {
                VSSUser user = this.VSS_Database.get_User(UserName);
                this.DatabaseGetUserCount += 1L;
                user.RemoveProjectRights(ProjectPath);
                this.UserRemoveRightsCount += 1L;
            }
            catch (Exception exception)
            {
                return exception.ToString();
            }
            return "";
        }

        public string Rename(string ItemPath, string NewName)
        {
            try
            {
                VSSItem item = this.VSS_Database.get_VSSItem(ItemPath, false);
                this.DatabaseGetItemCount += 1L;
                item.Name = NewName;
                this.SetItemNameCount += 1L;
                return "";
            }
            catch (Exception exception)
            {
                return exception.ToString();
            }
        }

        public string SetCurrentProject(string ProjectPath)
        {
            try
            {
                this.DatabaseSetCurrentProjectCount += 1L;
                this.VSS_Database.CurrentProject = ProjectPath;
            }
            catch (Exception exception)
            {
                return exception.ToString();
            }
            return "";
        }

        public string SetDefaultUserRights(int Rights)
        {
            try
            {
                this.VSS_Database.DefaultProjectRights = Rights;
                this.DatabaseSetDefaultRightsCount += 1L;
            }
            catch (Exception exception)
            {
                return exception.ToString();
            }
            return "";
        }

        public string SetFileType(string FilePath, bool Binary)
        {
            try
            {
                VSSItem item = this.VSS_Database.get_VSSItem(FilePath, false);
                this.DatabaseGetItemCount += 1L;
                item.Binary = Binary;
                this.SetItemTypeCount += 1L;
                return "";
            }
            catch (Exception exception)
            {
                return exception.ToString();
            }
        }

        public string SetUserRights(string ProjectPath, string UserName, int Rights)
        {
            try
            {
                VSSUser user = this.VSS_Database.get_User(UserName);
                this.DatabaseGetUserCount += 1L;
                user.set_ProjectRights(ProjectPath, Rights);
                this.UserSetRightsCount += 1L;
            }
            catch (Exception exception)
            {
                return exception.ToString();
            }
            return "";
        }

        public string SetWorkingFolder(string ItemPath, string LocalFolder)
        {
            try
            {
                this.VSS_Database.get_VSSItem(ItemPath, false).LocalSpec = LocalFolder;
                this.SetItemCheckOutFolderCount += 1L;
            }
            catch (Exception exception)
            {
                return exception.ToString();
            }
            return "";
        }

        public string ShareItem(string ShareTarget, string ItemToShare, string Comment, int Flags)
        {
            try
            {
                VSSItem item = this.VSS_Database.get_VSSItem(ShareTarget, false);
                VSSItem pIItem = this.VSS_Database.get_VSSItem(ItemToShare, false);
                this.DatabaseGetItemCount += 1L;
                item.Share(pIItem, Comment, Flags);
                this.ShareItemCount += 1L;
            }
            catch (Exception exception)
            {
                return exception.ToString();
            }
            return "";
        }

        public string UnCheckOutItem(string ItemToUnCheckOut, string UnCheckOutPath, int Flags)
        {
            try
            {
                this.VSS_Database.get_VSSItem(ItemToUnCheckOut, false).UndoCheckout(UnCheckOutPath, Flags);
                this.UnCheckOutItemCount += 1L;
            }
            catch (Exception exception)
            {
                return exception.ToString();
            }
            return "";
        }

        private string UserPassword(string Password)
        {
            return (this.CurrentPassword = Password);
        }

        private enum Latest
        {
            Comment = 1,
            Date = 4,
            Label = 2,
            LabelComment = 5,
            VersionNumber = 3
        }
    }
}

